#include "Exception.h"
BasicException::BasicException(string _w, string _file, string _function, int _l)
	:std::exception(),m_errorMessage(_w),m_file(_file),m_function(_function),m_line(_l),m_output("")
{
	Description();
}

BasicException::~BasicException()
{

}

void BasicException::Dump()
{
	static ofstream m_file("EngineError.log");
	m_file<<m_output;
}

const char* BasicException::what() const
{
	return m_output.c_str();
}

void BasicException::Description()
{
	stringstream rt;
	rt<<"Error:"<<m_errorMessage<<" raise!"<<endl;
	rt<<"File:"<<m_file<<endl;
	rt<<"Function:"<<m_function<<endl;
	rt<<"Line:"<<m_line<<endl;
	m_output=rt.str();
}


void DX11Exception::Description()
{
	stringstream rt;
	rt<<"Error:"<<m_errorMessage<<endl;
	if(m_info!="")
		rt<<"Info:"<<m_info<<endl;
	rt<<"File:"<<m_file<<endl;
	rt<<"Function:"<<m_function<<endl;
	rt<<"Line:"<<m_line<<endl;
	rt>>m_output;
}

DX11Exception::DX11Exception(string _err, string _info,string _file, string _function, int _l)
	:BasicException(_err,_file,_function,_l), m_info(_info)
{
}

DX11Exception::~DX11Exception()
{
}

FileException::FileException(string _f,FILE_ERROR_FORMAT _m, string _file, string _function, int _i)
	:BasicException(_f,_file,_function,_i),m_format(_m)
{ 
}

FileException::~FileException()
{
}

void FileException::Description()
{
	stringstream rt;
	rt<<"File:"<<m_errorMessage;
	switch(m_format)
	{
	case FAILED_OPEN:
		rt<<" can not open."<<endl;
		break;
	case FAILED_WRITE:
		rt<<" can not write"<<endl;
		break;
	case FAILED_READ:
		rt<<" can not read"<<endl;
		break;
	default:
		break;
	}
	rt<<"At file:"<<m_file<<endl;
	rt<<"Function:"<<m_function<<endl;
	rt<<"Line:"<<m_line<<endl;
	rt>>m_output;

}
